from ui.widgets import QCellWidget

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class CellView(ni.View):
    data = ni.List()
    headers = ni.List(item_type=ni.String())
    group = ni.List(exp_args=("item",))
    relations = ni.List(exp_args=("item",))
    show_editors = ni.Bool(default=False)
    expanded = ni.Bool(default=False)
    
    widget = QCellWidget
        
    #def update(self, *args):
    #    self.on_data_change(None)
        
    #def update_widget(self, widget):
       # print 'DATA', self.data
        #widget.model().group_fn = self.group
        #widget.model()._data = self.data
        #widget.model().relations = self.relations
        #widget.model().headers = self.headers
        #widget.model().reset()
        #if not self.relations:
        #    widget.header().hide()
        #else:
        #    widget.header().show()
        #widget.header().setResizeMode(QHeaderView.ResizeToContents)
        
        #if self.expanded:
        #    widget.expandAll()
            
        #widget.resizeColumnsToContents()
        #self.delegate = AttrDelegate()
        #widget.setItemDelegate(self.delegate)
    
        #widget.connect(widget.header(), SIGNAL("sectionResized(int,int,int)"), self.section_resized )
        
        #if self.show_editors:
        #    widget.open_all_editors()
        
    def section_resized(self, *args, **kw):
        for widget in self.widgets:
            widget.model().emit(SIGNAL("layoutChanged()"))
    
        
    def set_delegates(self, widget):
        pass
        
    def set_item_editors(self, widget):
        self.editors[widget] = []
        for item in widget.model().items():
            if item is None: continue
            editor = cmds.editor(item.data_obj)
            if not editor: continue
            if issubclass(editor, Editor):
                index = self.model().indexFromItem(item)
                editor_inst = editor(item.data_obj)
                self.widget.setItemDelegate()